/**
 * @description:
 * @author: LuoXiaoQiang
 * @date: 5/10/2025 1:16 AM
 * Copyright (c) 2025, LXQ Cloud All Rights Reserved.
 */
package com.lxq.rental.property.controller;

import com.lxq.rental.property.dto.PropertyDTO;
import com.lxq.rental.property.model.Property;
import com.lxq.rental.property.service.PropertyService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/properties")
public class PropertyController {

    private final PropertyService propertyService;

    public PropertyController(PropertyService propertyService) {
        this.propertyService = propertyService;
    }

    @GetMapping
    public List<Property> getAllProperties() {
        return propertyService.getAllProperties();
    }

    @GetMapping("/{id}")
    public Property getPropertyById(@PathVariable Long id) {
        return propertyService.getPropertyById(id);
    }

    @PostMapping
    public Property createProperty(@RequestBody PropertyDTO dto) {
        return propertyService.createProperty(dto);
    }

    @PutMapping("/{id}")
    public Property updateProperty(@PathVariable Long id, @RequestBody PropertyDTO dto) {
        return propertyService.updateProperty(id, dto);
    }

    @DeleteMapping("/{id}")
    public void deleteProperty(@PathVariable Long id) {
        propertyService.deleteProperty(id);
    }
}